Compiling and vbc.exe

Objective


Discussion

Compiling

Commenting Code

Writing Programs Without Visual Studio

Compiling with vbc.exe

Back to top
Demonstration

In this example we will create a simple VB program in Notepad, compile and run it. 

1.  Type the following code into a blank Notepad document.

Module Module1
    Public Sub Main()
        system.console.writeline("Hello World")
    end sub
end module

2.  Save the file as hello.vb. You can either save your hello.vb file in the same directory as the vbc.exe file or you can save hello.vb wherever you prefer and then copy the vbc.exe file into that directory. Depending on the setup of your computer you may need to follow this latter approach and your teacher may need to provide vbc.exe.

3. Open a Command Prompt window.  You can open a window in Windows XP by choosing the following in the start menu:

start.All Programs.Accessories.Command Prompt

You can also open the Command Prompt window by choosing Start.Run and entering "command".

4.  In the Command Prompt window, change your directory to the directory that your hello.vb and vbc.exe file are in.  If you are not familiar with how to do this, then follow the following steps. 

CD WINDOWS\Microsoft.NET\Framework\v1.0.3705

5.  Now that you are in the same directory as vbc.exe and hello.vb, compile your hello.vb program by typing the following:

vbc.exe hello.vb

6.  Run your program by typing the following:

hello

Hopefully you will get the  message "Hello World".  Pretty exciting, huh?  This program is the most simple (and boring) program that you will ever write using VB.

Back to top
Exercises

1.  This exercise will have you create a slightly more complicated program.   The code shown below is more like what you will see when you use Visual Studio to create your programs except that it is still much simpler.  In the code below , a class (Message) is defined and then an object (myMessage) of this type of class is created.  Then the method printMessage() of the class is called.  Notice that many of the lines have comments.   Don't worry too much about the details at this point.

Imports system  'Imports system namespace
class Message  'Defines a class
    dim sX as string = "Hello World" 'Declares and initializes a string
    public sub printMessage() 'Sub for printing the message
        console.writeLine(sX)
    end sub
end class
Module Module1
    Public Sub Main()  'Will run when program is executed
        dim myMessage as Message 'Declares a variable that will be a Message 
        myMessage = new Message() 'Creates myMessage and assigns memory
        myMessage.printMessage() 'calls the printmessage method
    end sub
end module

a.  Before testing the code, try to figure out what it will do.
b.  Type or copy and paste the code in Notepad, compile and run it.
c.  Modify the program so that it displays a different message. 
d.  Modify the program so that the message appears on multiple lines.

2.  Write a program that "draws" a letter by forming it as a mosaic of the letter.  For example, if the letter is a "T" then your display should look like the following when the program runs:

Exercise 2  

3.  Refer to the Help article "The Visual Basic Version of Hello World!"  Create a program that you compile and run from the command prompt and that displays "Hello World" in a messagebox.  Note that another (older) way to display a messagebox is to use msgbox("message here").  You should use this approach in your program. Also, you may need to include the following statement at the top of your program to make your program work: "Imports microsoft.visualbasic".

4.  How do you make a comment in your program?  When do you use comments?

Back to top

Links & Help
Back to top